//第一模块,显示与隐藏
(function () {
  const elevator = document.querySelector('.city-elevator')
  const entry = document.querySelector('.city-elevator')
  window.addEventListener('scroll', function () {
    const n = document.documentElement.scrollTop
    elevator.style.opacity = n >= entry.offsetTop ? 1 : 1
  })
  const backTop = document.querySelector('#backTop')
  backTop.addEventListener('click', function () {
    window.scrollTo(0, 0)
  })
})();

//第二模块
(function () {
  const list = document.querySelector('.city-elevator-list')
  list.addEventListener('click', function (e) {
    if (e.target.tagName == 'A') {
      const old = document.querySelector('.city-elevator-list .active')
      if (old) old.classList.remove('active')
      //当前元素添加'active'
      e.target.classList.add('active')
      //获得自定义属性
      console.log(e.target.dataset.name);
      const top = document.querySelector(`.${e.target.dataset.name}`)
      console.log(top);
      console.log(111);
      console.log(top.offsetTop);
      document.documentElement.scrollTop = top.offsetTop
    }
  })
})();